//
//  ViewController.m
//  28-UIViewAnimation
//
//  Created by dllo on 16/8/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"

@interface ViewController ()
@property (nonatomic,strong) UIView *animationView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)];
    _animationView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationView];
//    UIViewAnimation 方法
//   1 开始设置动画
//    参数1:动画标识 参数2：上下文
    [UIView beginAnimations:nil context:NULL];
//    2设置动画曲线，如何进行动画
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
//   3 设置动画持续时间
    [UIView setAnimationDuration:10];
//    _animationView.fll_x = 100;
//    4动画延时
//    [UIView setAnimationDelay:10];
//    [UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:10]];
//    动画车重复次数
    [UIView setAnimationRepeatCount:2.5];
//    设置往返动画，一个来回算一次
    [UIView setAnimationRepeatAutoreverses:YES];
//    是否忽略
    [UIView setAnimationsEnabled:YES];
//    5动画的改变
    _animationView.fll_width = self.view.fll_width;
    
//    动画的代理不签订代理不执行
//    将要开始
//    将要结束
    [UIView setAnimationDelegate:self];
    [UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
    [UIView setAnimationWillStartSelector:@selector(animationDidStart:)];
    [UIView setAnimationDidStopSelector:@selector(animationDidStart:)];
    
//  6  结束动画设置，执行该动画，
    
    [UIView commitAnimations];
    
//    7
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        for (int i = 0; i < 101; i++) {
//        _animationView.fll_x = i;
//    }
//    });
    
//    UIViewAnimationCurveEaseInOut,开始和结束时缓慢
//    UIViewAnimationCurveEaseIn,开始时缓慢
//    UIViewAnimationCurveEaseOut,结束时缓慢
//    UIViewAnimationCurveLinear匀速
    
    
//    UIViewAnimationblock
//    持续时间
//    block，需要执行的动画效果
    [UIView animateWithDuration:5 animations:^{
        _animationView.fll_x = 300;
    }];
//    完成后需要执行的操作
    [UIView animateWithDuration:5 animations:^{
        _animationView.fll_x = 300;
    } completion:^(BOOL finished) {
        NSLog(@"动画完成后需要执行的操作");
    }];
//    延迟
//    选项枚举，按位枚举1<<0,多选
    [UIView animateWithDuration:5 delay:5 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
        _animationView.fll_x = 300;
    } completion:^(BOOL finished) {
         NSLog(@"动画完成后需要执行的操作");
    }];
    
    
    
    
    
    
    
}

- (void)animationWillStart:(NSString *)animationID context:(void *)context
{
    NSLog(@"动画将要开始");
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    
    NSLog(@"动画已经结束");
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
